// pages/mv-detail/mv-detail.js
import {
  getMvUrl,
  getMvDetail
} from "../api/music"
const colors = [
  "#ff0000",
  "'#ff00ff",
  "#00ffff",
  "#0000ff",
  "#00ff00"
]
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url: "",
    mvInfo: "",
    value: "",
    text: "",
    danmuList: [{
      text: '第 1s 出现的弹幕',
      color: '#ff0000',
      time: 1
    }, {
      text: '第 3s 出现的弹幕',
      color: '#ff00ff',
      time: 3
    }],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.id);
    getMvUrl(options.id).then(res => {
      this.setData({
        url: res.data.data.url
      })

    })
    getMvDetail(options.id).then(res => {
      console.log(res);
      this.setData({
        mvInfo: res.data.data
      })
    })

  },
  onReady() {
    this.videoContext = wx.createVideoContext('mvvideo')
  },
  // 随机生成随机数colors长度
  bindSendDanmu() {
    const randomnNum = Math.floor(Math.random() * colors.length)
    this.videoContext.sendDanmu({
      text: this.data.value,
      color: colors[randomnNum]
    })
    console.log(this.data.value);
    console.log(colors[randomnNum]);
    console.log(this.videoContext.sendDanmu);

    // console.log(this.vdioContext.sendDanmu);

  }








})